package leetcode;

import java.util.ArrayList;
import java.util.List;

public class SummaryRanges {

	public static void main(String[] args) {
		SummaryRanges object = new SummaryRanges();
		int[] nums = {0, 1, 2, 5, 6, 9};
		System.out.println(object.summaryRanges(nums));
	}
	
	public List<String> summaryRanges(int[] nums) {
        List<String> list = new ArrayList<>();
        if(nums == null){
            return list;
        }
        int start = nums[0];
        int end = nums[0];
        for(int i = 1; i < nums.length; i++){
            if(nums[i] - 1 == nums[i - 1]){
            	end = nums[i];
            	continue;
            }
            if(end == start){
                list.add(start + "");
            }else{
                list.add(start + "->" + end);
            }
            start = nums[i];
            end = nums[i];
        }
        if(end == start){
            list.add(start + "");
        }else{
            list.add(start + "->" + end);
        }
        return list;
    }
}
